import time
from threading import Lock

from concurrent.futures import ThreadPoolExecutor

from db import Tthread

def get_or_create(thread_id,lock):
    with lock:
        Tthread.get_or_create(thread_id=thread_id)
    
def main():
    lock = Lock()
    pool = ThreadPoolExecutor(max_workers=3)
    for i in range(100):
        pool.submit(get_or_create,i,lock)
        pool.submit(get_or_create,i,lock)
        pool.submit(get_or_create,i,lock)
    pool.shutdown()
    
if __name__=='__main__':
    main()